<?php

namespace App\Repositories;


use App\Custom\Wechat\Main as WechatMain;
use App\Exceptions\ConditionException;
use Carbon\Carbon;

abstract class BaseRepository
{

    use WechatMain;



    /**
     * 发送订阅消息
     * @param $templateId
     * @param $toUser
     * @param $map
     * @param string $page
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function sendTemplateMessage($templateId, $toUser, $map, $page = '')
    {
        try {
            $data = [
                'template_id' => $templateId, // 所需下发的订阅模板id
                'touser' => $toUser,     // 接收者（用户）的 openid
                'page' => $page,       // 点击模板卡片后的跳转页面，仅限本小程序内的页面。支持带参数,（示例index?foo=bar）。该字段不填则模板无跳转。
                'data' => $map,
            ];
            $app =  $this->getWechatApp();
            $result = $app->subscribe_message->send($data);
        } catch (\Exception $exception) {
            \Log::info('消息推送失败:' . $exception->getMessage());
        }
    }

}
